package cn.school.classManage.service.impl;

import cn.school.classManage.dao.ClassCurriculumDetailDao;
import cn.school.classManage.entity.ClassCurriculumDetail;
import cn.school.classManage.service.ClassCurriculumDetailService;
import cn.school.common.utils.SysUserUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

@Service
public class ClassCurriculumDetailServiceImpl extends ServiceImpl<ClassCurriculumDetailDao, ClassCurriculumDetail> implements ClassCurriculumDetailService {

    @Override
    public int addOrUpdateDetail(ClassCurriculumDetail entity) {
        String username = SysUserUtils.getSysUser().getUsername();
        int num=0;
        if(StringUtils.isEmpty(entity.getId())){
            entity.setCreateTime(new Date());
            entity.setCreateBy(username);
            num=this.baseMapper.insert(entity);
        }else{
            entity.setModifyTime(new Date());
            entity.setModifyBy(username);
            num=this.baseMapper.updateById(entity);
        }
        return num;
    }

    @Override
    public int deleteDetail(ClassCurriculumDetail entity) {
        return baseMapper.deleteById(entity.getId());
    }
}
